package com.lpit.controller;

import com.lpit.result.ResponseResult;
import com.lpit.dto.ArticleHomeDto;
import com.lpit.pojo.Article;
import com.lpit.service.ArticleService;
import com.lpit.zookeeper.Sequences;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Administrator
 */
@RestController
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @Autowired
    private Sequences sequence;

    @GetMapping("/select.list")
    public ResponseResult<List<Article>> load(ArticleHomeDto article){
        /*TransactionSynchronizationManager.isActualTransactionActive()可以测试是否处于事务内*/
        return articleService.selectList(article);
    }

    @GetMapping("/test")
    public ResponseResult<List<Article>> loadNew(Article article) throws Exception {
        System.err.println("Controller");
        Long aLong = sequence.sequenceUser();
        Long aLong1 = sequence.sequenceArticle();
        System.err.println("主键："+aLong);
        System.out.println("aLong1 = " + aLong1);
        return null;
    }


    /**
     * 累计文章阅读数
     */
    @GetMapping("/readSum")
    public ResponseResult<Long> getReadSum(){
        return articleService.getReadSum();
    }
}
